package mymyoux.utils
{
	public class Vectors
	{
		private var _size:uint;
		private var _compos:Vector.<Number>;
		public function Vectors(size:uint, ...composantes)
		{
			_size = size;
			if(composantes != null && composantes.length > 0)
			{
				_size = composantes.length;
				_compos = new Vector.<Number>(_size);
				for(var i:uint = 0; i < _size; i++)
				{
					_compos[i] = composantes[i];
				}
			}else
			{
				_compos = new Vector.<Number>(_size);
			}
			
		}
		public function get size():uint
		{
			return _size;
		}
		public function getAngle(id:uint):Number
		{
			if(id < _size)
			{
				return Math.acos(_compos[id]/norme)/Math.PI * 180;
			}else
			{
				return 0;
			}
		}
		public function setAngle(...angles):void
		{
			if(angles != null && angles.length == _size)
			{
				var n:Number = norme;
				for(var i:uint = 0; i < _size ; i++)
				{
					//if
					_compos[i] = n * Math.cos(angles[i]);
				}
			}
			
			
		}
		public function getComposante(id:uint):Number
		{
			if(id < _size)
			{
				return _compos[id];
			}else
			{
				return 0;
			}
		}
		public function setComposante(id:uint, value:Number):void
		{
			if(id < _size)
			{
				_compos[id] = value;
			}
		}
		public function add(vector:Vectors):Vectors
		{
			if(vector.size == _size)
			{
				var v:Vectors = new Vectors(_size);
				for(var i:uint = 0; i < _size; i++)
				{
					v.setComposante(i, vector.getComposante(i) + _compos[i]);
				}
				return v;
			}else
			{
				return null;
			}
			
		}
		public function get norme():Number
		{
			var n:Number = 0;
			for(var i:uint = 0; i < _size ; i++)
			{
				n+=Math.pow(_compos[i], 2);
			}
			return Math.sqrt(n);
		}
		public function toString():String
		{
			var result:String = "[Vector (";
			for(var i:uint = 0; i < _size ; i++)
			{
				result+=_compos[i]+",";
			}
			result = result.substring(0, result.length -1)+") norme=\""+norme+"\" angle=\"(";
			for(i = 0; i < _size ; i++)
			{
				result+=Maths.round(getAngle(i), 2)+",";
			}
			return result.substring(0, result.length -1)+	")]";
		}
	}
}